-
-
Notifications
You must be signed in to change notification settings - Fork 818
Make ByteSourceJsonBootstrapper use StringReader for < 8KiB byte[] inputs
#1081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
| if (in == null) { | ||
| int length = _inputEnd - _inputPtr; | ||
| if (length >= 0 && length <= 8192) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit: It may not be worth checking length >= 0. It has a small perf impact and the length is very unlikely to negative and will just fail at the ByteArrayInputStream stage anyway. The length == 0 case will probably be more tidily handled with the StringReader than the ByteArrayInputStream route.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I flipped the condition to short circuit for large inputs first if (length <= STRING_READER_BYTE_ARRAY_LENGTH_LIMIT && length >= 0).
I'd prefer to keep the length >= 0 as the array length check here should be negligible, and ensures the ByteInputStream continues handling any negative array length path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking it through over night, I removed the length >= 0 condition.
ByteSourceJsonBootstrapper use StringReader for < 8KiB byte[] inputs
|
Ok I assume this has been benchmarked and since it only affects what I assume is minority use case (non-UTF-8 input that comes as byte input), I am ok merging it. Thank you @schlosna ! |
Optimize to avoid allocation of heap ByteBuffer via InputStreamReader. Remove after upgrade to Jackson 2.16. see: FasterXML/jackson-core#1081 and FasterXML/jackson-benchmarks#9
Optimize to avoid allocation of heap ByteBuffer via InputStreamReader. Remove after upgrade to Jackson 2.16. see: FasterXML/jackson-core#1081 and FasterXML/jackson-benchmarks#9
Now that AtlasDB has upgraded to Jackson 2.16.1, remove performance workaround that landed upstream in Jackson 2.16.0. See FasterXML/jackson-core#1081
Now that AtlasDB has upgraded to Jackson 2.16.1, remove performance workaround that landed upstream in Jackson 2.16.0. See FasterXML/jackson-core#1081 Removes changes from #6750
Since FasterXML/jackson-core#1081 this optimization does no longer make sense as it's applied internally by Jackson if needed.
Since FasterXML/jackson-core#1081 this optimization does no longer make sense as it's applied internally by Jackson if needed.
Avoid InputStreamReader / HeapByteBuffer overhead for small (less than 8KiB) inputs, see FasterXML/jackson-core#1081
Avoid InputStreamReader / HeapByteBuffer overhead for small (less than 8KiB) inputs, see FasterXML/jackson-core#1081
Avoid InputStreamReader / HeapByteBuffer overhead for small (less than 8KiB) inputs, see FasterXML/jackson-core#1081
Avoid `InputStreamReader` / `HeapByteBuffer` overhead for small (less than 8KiB) inputs, see FasterXML/jackson-core#1081 and FasterXML/jackson-benchmarks#9 (comment) for benchmarks showing between 2x and 10x speedup handling deserialization of small values.
From @carterkozak #1079 (comment) this is an alternative implementation draft to address #593 (and #995 (comment) ) when deserializing from a
byte[]as theInputStreamReadercode path triggers an 8KiBHeapByteBufferallocation forStreamDecoderregardless of input byte array length. This allocation significantly penalizes smallerbyte[]sources.The approach here converts
byte[]inputs smaller thank 8KiB to aStringand processed viaStringReader. This should avoid unnecessary 8KiB heap byte buffer allocation and leverage OpenJDK's continued charset decoding improvements (e.g. https://cl4es.github.io/2021/02/23/Faster-Charset-Decoding.html ).Initial benchmarks from FasterXML/jackson-benchmarks#9 show
StringReaderproviding performance equivalent toByteArrayInputStreamsource in worst case, and anywhere from ~2x to ~10x speedup in best case.